<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Index</title>
</head>

<body>
    <div id="app">
        <h2 style="border-bottom: 2px solid rgba(0, 0, 0, 0.3);">
            Vue 数组更新方法(触发响应式)
        </h2>
        <button @click="pustBtn">push()</button>
        <button @click="popBtn">pop()</button>
        <button @click="shiftBtn">shift()</button>
        <button @click="unshiftBtn">unshift()</button>
        <button>splice()</button>
        <button>sort()</button>
        <button>reverse()</button>
        <ul>
            <li v-for="(item, index) in arr" :key="index">
                {{item}}
            </li>
        </ul>

        <h2 style="border-bottom: 2px solid rgba(0, 0, 0, 0.3);">
            替换数组
        </h2>
        <button>fliter()</button>
        <button>concat()</button>
        <button>slice()</button>
    </div>
</body>

<script src="../js/vue.js"></script>
<script>
    const vm = new Vue({
        el: '#app',
        data() {
            return {
                arr: [1, 2, 3],
            }
        },
        methods: {
            pustBtn() {
                console.log(this.arr.push(9));;
            },
            popBtn() {
                console.log(this.arr.pop());
            },
            shiftBtn() {
                console.log(this.arr.shift());
            },
            unshiftBtn() {
                console.log(this.arr.unshift('k'));
            }
        },
    });

    const arr1 = [1, 2, 3, 4, 5];
    arr1.splice(0, 3);
    console.log(arr1);

    const arr2 = [1, 2, 3, 4, 5];
    arr2.splice(0, 3, 'k', 8, 's');
    console.log(arr2);

    const arr3 = [1, 2, 3, 4, 5];
    console.log(arr3.slice(1, 3));
</script>

</html>